package com.example.springmvc.handler;

import com.example.springmvc.pojo.Dept;
import com.example.springmvc.pojo.User;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ModelAttribute;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * @Description: 全局数据绑定
 * @Author: lijiewei
 * @Date: 2020/7/15$ 22:20$
 */
@ControllerAdvice
public class InitDataHandler {

    @ModelAttribute(name = "myDept")
    public Dept initData() {
        Dept dept = new Dept();
        dept.setName("开发部");
        dept.setInfo("开发部");
        return dept;
    }

//    @ModelAttribute
//    public Map<String, String> personModelAttr(HttpServletRequest request) {
//        request.setAttribute("data", "request中放的数据");
//        Map<String, String> map = new HashMap<>();
//        map.put("data", "request中放的数据");
//        return map;
//    }
}
